package cn.damai.mine.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestCachedThreadPool {
	
	public static void main(String[] args) {
		
		ExecutorService executorService = Executors.newCachedThreadPool();
//		ExecutorService executorService = Executors.newFixedThreadPool(5);
//		ExecutorService executorService = Executors.newSingleThreadExecutor();
		
		for(int i = 0;i < 5;i++){
			executorService.execute(new TestRunnnable());
			System.out.println("************* a" + (i + 1) + " *************"); 
		}
		executorService.shutdown();
	}
}

class TestRunnnable implements Runnable{

	@Override
	public void run() {
		// TODO Auto-generated method stub
		System.out.println(Thread.currentThread().getName() + "线程被调用了。");
		
		try {
			Thread.sleep(1000);
			System.out.println("当前线程名称："+Thread.currentThread().getName());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
